package com.edu.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.edu.entity.User;
import com.edu.entity.userFollow;
import com.edu.service.impl.myFollowServiceImpl;

/**
 * Servlet implementation class addFollowServlet
 */
@WebServlet(name = "addFollowDo", urlPatterns = { "/addFollowDo" })
public class addFollowServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		User u = (User) session.getAttribute("logInUser");
		myFollowServiceImpl msi = new myFollowServiceImpl();
		String getSellerId = request.getParameter("sellerid");
		int sellerid= Integer.parseInt(getSellerId);
		System.out.println("关注对象id为："+sellerid);
		boolean out1 = request.getParameter("add") != null;
		boolean out2 = request.getParameter("del") != null;
		boolean hasFollow = false;
		
		if(out1) {
			if(msi.addFollow(u.getUserid(), sellerid) > 0) {
				System.out.println("关注成功！");
			}else {
				System.out.println("关注失败！");
			}
		}else if(out2) {
			if(msi.unfollowUser(u.getUserid(), sellerid)) {
				System.out.println("取关成功！");
			}else {
				System.out.println("取关失败！");
			}
		}
		request.getRequestDispatcher("sellerInfo").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
